//### 编码：UTF-8

//### 单个超链接的 属性href获取
//### A_GetHrefById
function A_GetHrefById(_id)
{
	var AA = document.getElementById(_id);
	return AA.href;
}
//A_getHrefById('AA01')

//### 多个超链接的 属性href获取(数组)
//### AA_GetHrefByTagName
function AA_GetHrefByTagName(_tagName)
{
	var AA = document.getElementsByTagName('a');
	var hrefs = [];
	for( var i = 0; i < AA.length; i++)
		hrefs[i] = AA[i].href;
	console.log(hrefs);
	return hrefs;
}
//AA_GetHrefByTagName('a');


//### 找到淘宝登陆界面的 <div class="login-newbg" ></div>，将其删掉
//### 淘宝登陆界面网址：https://login.taobao.com/member/login.jhtml
//### TB_DeleteFirstElementByClassName
function TB_DeleteFirstElementByClassName(_tagName, _className)
{
	var dd = document.getElementsByTagName(_tagName);
	for( var i = 0; i < dd.length; i++)
	{
		if (dd[i].className == _className)
		{
			dd[i].parentNode.removeChild(dd[i]);
			break;
		}
	}
}
//TB_DeleteFirstElementByClassName('div', 'login-newbg');


//### 根据id，删除网页上的某个元素
//### TB_DeleteElementById
function TB_DeleteElementById(_id)
{
	var element = document.getElementById(_id);
	if (element)
		element.parentNode.removeChild(element);
}
//TB_DeleteElementById('stblogo');


//### 登陆上taobao之后，来到网址"https://i.taobao.com/my_taobao.htm"，然后模拟在input中输入需要查找的文字，然后点击Button"搜 索"
//### 往<input type="text"/>中填入信息
//### TB_input_setValueById
function TB_input_setValueById(_id, _value)
{
	var q = document.getElementById(_id);
	if (q)
		q.value = _value
}
//TB_input_setValueById('q', '水杯')

//### 根据className，点击网页上的<button/>元素
//### TB_ButtonClick_byClassName
function TB_ButtonClick_byClassName(_className)
{
	var btns = document.getElementsByTagName('button');
	for( var i = 0; i < btns.length; i++)
	{
		if (btns[i].className == _className)
		{
			btns[i].click();
			break;
		}
	}
}
//TB_ButtonClick_byClassName('btn-search');


//### 通过tagName找一类元素，再通过innerText定位具体某个元素，然后点击
//### Click_by_TagName_innerText
function Click_by_TagName_innerText(_tagName, _innerText)
{
	var AA = document.getElementsByTagName(_tagName);
	for( var i = 0; i < AA.length; i++)
	{
		if (AA[i].innerText == _innerText)
		{
			AA[i].click();
			break;
		}
	}
}

//### 通过_tagName和_className 找到第一个符合条件的节点
//### Element_by_tagName_className
function Element_by_tagName_className(_tagName, _className)
{
	var AA = document.getElementsByTagName(_tagName);
	for( var i = 0; i < AA.length; i++)
	{
		if (AA[i].className == _className)
			return AA[i];
	}

	return null;
}

//### 获取：某个节点的innerText
//### InnerText_by_Element
function InnerText_by_Element(_element)
{
	if (_element)
		return _element.innerText;

	return "";
}

//### 获取：某一个节点下，tagName为_tagName的第一个节点的innerText
//### InnerText_by_parent_tagName
function InnerText_by_parent_tagName(_parentElement, _tagName)
{
	var AA = document.getElementsByTagName(_tagName);
	for( var i = 0; i < AA.length; i++)
	{
		if (AA[i].parentNode == _parentElement)
			return AA[i].innerText;
	}

	return "";
}


//### 商铺列表，获取商铺的名称和链接
//### ShopInfoList
function ShopInfoList()
{
	var rst = [];
	var ul = document.getElementById('list-container');
	console.log("ul: "+ul);
	if (ul)
	{
		var h4h4 = ul.getElementsByTagName('h4');
		console.log("h4h4: "+h4h4+", h4h4.length: "+h4h4.length);
		if (h4h4)
		for(var i = 0; i < h4h4.length; i++)
		{
			var aa = h4h4[i].getElementsByTagName('a');
			if (aa)
			{
				rst[2*i+0] = aa[0].innerText;
				rst[2*i+1] = aa[0].href;

				console.log("aa[0]: "+aa[0]);
				console.log("aa[0].innerText: "+aa[0].innerText);
				console.log("aa[0].href: "+aa[0].href);
			}
		}
	}

	return rst;
//	return "";
}

//### 滚动窗口. 参数：_direction滚动的方向(0:scrollLeft;1:scrollTop); _scroll滚动多少(数值[不能带单位(如px等)])
//### ScrollWindow
function ScrollWindow(_direction, _scroll)
{
	//例子: "document.body.scrollTop=500;"
	if (_direction == 0)
	{
		document.body.scrollLeft = _scroll;
		var htmls = document.getElementsByTagName('html');
		if (htmls)
			htmls[0].scrollLeft = _scroll;
	}
	else if (_direction == 1)
	{
		document.body.scrollTop = _scroll;
		var htmls = document.getElementsByTagName('html');
		if (htmls)
			htmls[0].scrollTop = _scroll;
	}
}

//### 修改某网页元素的 某属性的属性值(最先用于将某input的type属性设置为'password')
//### element_SetType
function element_SetType(_element, _attrName, _attrValue)
{
	//q['type'] = 'password';
	//q.type = 'password';
	_element[_attrName] = _attrValue;
}

//### 淘宝网页登陆，填入用户名
//### TB_SetLoginUsername
function TB_SetLoginUsername(_id, _value)
{
	var ele = document.getElementById(_id);
	if (ele)
	{
		ele['type'] = 'password';
		ele.value = _value
	}
}


//###